#! /usr/bin/env node

let axios = require('axios');
let url = 'http://fanyi.youdao.com/openapi.do?keyfrom=toaijf&key=868480929&type=data&doctype=json&version=1.1&q=';
let chalk = require('chalk')
if (process.argv[2]) {
    axios.get(url + encodeURI(process.argv[2])).then(res => {
        if (res.data.errorCode == 0 && res.data.web) {
            for (let i = 0; i < res.data.web.length; i++) {
                for (const key in res.data.web[i]) {
                    console.log(`${chalk.green(key)}:${chalk.blue(res.data.web[i][key]) }`)
                }
            }
            console.log(res.data.translation[0])
        } else if (res.data.errorCode == 0) {
            console.log(res.data.translation[0])
        }
    })
} else {
    console.log('缺少参数');
}